<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 题目1(选做)：const arr=['name','age','hhh','hhh','age','hhh','hhh','hhh'] 元素各出现多少次
      // 要求输出一个对象如下：{age: 2,hhh: 5,name: 1}
      const arr = ['name', 'age', 'hhh', 'hhh', 'age', 'hhh', 'hhh', 'hhh']
      let obj = {}
      for (let k in arr) {
        console.log(arr[k])
        //如果obj 没有这一项  就让这一项为1  ，有这一项 就让这一项 +1
        if (!obj[arr[k]]) {
          obj[arr[k]] = 1
        } else {
          obj[arr[k]]++
        }
      }

      console.log(obj)
    </script>
  </body>
</html>
